package web.it.thymeleaf.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import web.it.thymeleaf.model.goods;

import java.util.ArrayList;
import java.util.List;

/**
 * jsp
 */
@Controller
public class IndexController {
    private  static final Logger log= LoggerFactory.getLogger(IndexController.class);
    @RequestMapping("/hello")
    public  String index(Model model, HttpServletRequest request){
        model.addAttribute("name","张三");
        model.addAttribute("blow",
                request.getHeader("User-Agent").toLowerCase().contains("edg")?"微软edge":
                        request.getHeader("User-Agent").toLowerCase().contains("firefox")?"火狐浏览器":
                                request.getHeader("User-Agent").toLowerCase().contains("chrome")?"谷歌":"未知"
        );
//        model.addAttribute("name","李四");
//        model.addAttribute("ip",request.getRemoteAddr() );
        log.info(request.getRemoteAddr());
        return  "hello";
    }

    @RequestMapping("/login")
    public String login(Model model){
        List<goods> goodsList=new ArrayList<>();
        goods g1=new goods("冰红茶",2.0);
        goods g2=new goods("茉莉花茶",3.0);
        goodsList.add(g1);
        goodsList.add(g2);
        model.addAttribute("goodlist",goodsList);
        model.addAttribute("g1",g1);
        model.addAttribute("g2",g2);
        model.addAttribute("w","不知道");
        return "login";
    }
}
